package com.zhoust.threadbatch.controller;


import com.zhoust.threadbatch.entity.User;
import com.zhoust.threadbatch.service.IUserService;
import com.zhoust.threadbatch.service.impl.TaskServerImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoust
 */
@RestController
public class TestController {

    private final TaskServerImpl taskServer;


    private final IUserService iUserService;

    public TestController(IUserService iUserService,TaskServerImpl taskServer) {
        this.iUserService = iUserService;
        this.taskServer = taskServer;
    }

    @GetMapping("/getDate")
    public String getDate(){
        return iUserService.testRollBackOne();
    }


    @GetMapping("/saveUser")
    public String saveUser(){
        for (int i =0;i<50;i++){
            taskServer.saveUser(i);
        }

        return "succeed";
    }
    @GetMapping("/queryUser")
    public String queryUser(){

        ArrayList<Integer> integers = new ArrayList<>();
        List<User> users = iUserService.queryUser(integers);


        return users.toString();
    }


    @GetMapping("/testThread")
    public String testThread(){

        for (int i = 0; i < 100; i++) {
            taskServer.testThread1();
            taskServer.testThread2();
        }
        return "succeed";
    }
}
